﻿using System;
using System.IO;
using System.Xml;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;

namespace WoChu.RfClient.Common
{
    /// <summary>
    /// Summary description for Settings.
    /// </summary>
    public class FileAndListHelper
    {

        private static FileAndListHelper _NewInstance = new FileAndListHelper();

        public static FileAndListHelper NewInstance
        {
            get
            {
                if (_NewInstance == null)
                {
                    _NewInstance = new FileAndListHelper();
                }

                return _NewInstance;
            }
        }

        private List<string> readFileToList(string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            List<string> list = new List<string>();
            StreamReader m_streamReader = new StreamReader(fs);//中文乱码加上System.Text.Encoding.Default,或则System.Text.Encoding.GetEncoding("GB2312")
            //使用StreamReader类来读取文件
            m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
            // 从数据流中读取每一行，直到文件的最后一行，并在richTextBox1中显示出内容

            string strLine = m_streamReader.ReadLine();
            while (strLine != null)
            {
                list.Add(strLine);
                strLine = m_streamReader.ReadLine();
            }
            //关闭此StreamReader对象
            m_streamReader.Close();
            return list;

        }
        private void writeListToFile(List<string> pList, string myFileName)
        {
            //创建一个文件流，用以写入或者创建一个StreamWriter
            System.IO.FileStream fs = new System.IO.FileStream(myFileName, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter m_streamWriter = new StreamWriter(fs);
            m_streamWriter.Flush();
            // 使用StreamWriter来往文件中写入内容
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.Begin);
            // 把richTextBox1中的内容写入文件
            for (int i = 0; i < pList.Count; i++)
            {

                m_streamWriter.WriteLine(pList[i]);
            }
            //关闭此文件
            m_streamWriter.Flush();
            m_streamWriter.Close();
     

        }
    }
}
